package com.wangwei.spring.rabbit;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.support.converter.MessageConversionException;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.core.StandardReflectionParameterNameDiscoverer;

/**
 * 字符串的messageConverter
 * Created by wangwei on 2019/10/12 0012.
 */
public class TextMessageConverter implements MessageConverter {
    @Override
    public Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
        System.out.println("-----TextMessageConverter(toMessage)------");
        return new Message(object.toString().getBytes(),messageProperties);
    }

    @Override
    public Object fromMessage(Message message) throws MessageConversionException {
        System.out.println("--------TextMessageConverter(fromMessage)-------");
        return new String(message.getBody());
//        return message.getBody();
//        return new Body(message.getBody());
    }
}
